package com.ace3l.legal.gwt.studentportal.mainpage.client;

import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.HTMLPanel;
import com.gwtext.client.widgets.layout.VerticalLayout;
import com.gwtext.client.widgets.form.Label;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.ace3l.legal.gwt.domainmodule.client.StudentPortalServiceAsync;
import com.ace3l.legal.gwt.domainmodule.client.StudentPortalService;
import com.ace3l.legal.gwt.domainmodule.gwt.GWTProject;
import com.ace3l.legal.gwt.domainmodule.gwt.GWTLawFirm;

/**
 * Created by IntelliJ IDEA.
 * User: ageer
 * Date: Aug 18, 2008
 * Time: 6:56:28 PM
 * To change this template use File | Settings | File Templates.
 */
public class StudentProjectViewWidget extends Panel{
    private final Panel mainPanel = this;

    private final Panel pProjectInfo = new Panel();
    private final Panel pQuestions = new Panel();
    private final Panel pAttachments = new Panel();
    private final Panel pButtons = new Panel();

    private final Label lProjectTitle = new Label();
    private final Label lLawFirm = new Label();
    private final Label lStatus = new Label();
    private final Label lHours = new Label();
    private final Label lDueDate = new Label();

    private final HTMLPanel pDescription = new HTMLPanel();

    final StudentPortalServiceAsync studentService = StudentPortalService.App.getInstance();

    private AsyncCallback getProjectCallback = new AsyncCallback() {
        public void onFailure(Throwable caught) {
            lStatus.setText("Error retrieving project: " + caught.getMessage());
        }

        public void onSuccess(Object result) {
            GWTProject project = (GWTProject) result;
            GWTLawFirm lawFirm = project.getLawFirm();

            lProjectTitle.setText(project.getTitle());
            lLawFirm.setText("Owner: " + lawFirm.getLawFirmName() +
            "(" + lawFirm.getContactFirstName() + " " + lawFirm.getContactLastName() + ")");
            lStatus.setText(project.getWorkflowStage());
            lHours.setText("Hours: " + project.getHoursAllotted());
            lDueDate.setText("Due Date: " + project.getDueDate().toString());
            pDescription.setHtml(project.getDescription());

        }
    };

    public StudentProjectViewWidget(String projectId) {
        
        this.setWidth(700);
        this.setHeight(500);
        this.setAutoScroll(true);
        this.setLayout(new VerticalLayout(10));

        pProjectInfo.setWidth(700);
        pProjectInfo.setAutoHeight(true);
        pProjectInfo.setLayout(new VerticalLayout());
        pProjectInfo.add(lProjectTitle);
        pProjectInfo.add(lLawFirm);
        pProjectInfo.add(lStatus);
        pProjectInfo.add(lHours);
        pProjectInfo.add(lDueDate);

        pDescription.setWidth(700);
        pDescription.setAutoHeight(true);
        pDescription.setHeader(false);
        pDescription.setBorder(false);
        pProjectInfo.add(pDescription);

        this.add(pProjectInfo);
        this.add(pQuestions);
        this.add(pAttachments);
        this.add(pButtons);
        studentService.getProject(projectId, getProjectCallback);

    }
}
